package com.jz.community.moduleshopping.orderList.task;

import android.app.Activity;

import com.jz.community.basecomm.constant.AppConstants;
import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;
import com.jz.community.moduleshopping.orderList.bean.CouponInfoOrderBean;

import java.util.HashMap;
import java.util.List;

public class CouponInfoOrderTask extends RxTask<String, Integer, List<CouponInfoOrderBean>> {


    private Activity activity;
    private ITaskCallbackListener taskListener;

    public CouponInfoOrderTask(Activity activity,
                               ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected List<CouponInfoOrderBean> doInBackground(String... params) {
        String result = OkHttpUtil.get(Constant.COUPON_INFO_ORDER + "/" + AppConstants.APPID, getParam(params[0]));
        List<CouponInfoOrderBean> bean = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            bean = JsonUtils.parseArray(result, CouponInfoOrderBean.class);
        }
        return bean;
    }


    @Override
    protected void onPostExecute(List<CouponInfoOrderBean> result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        ProgressDialogManager.dismissProgressDialog();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        ProgressDialogManager.showDialog(activity);
        super.onPreExecute();
    }

    private HashMap<String, Object> getParam(String orderIds) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("orderIds", orderIds);
        return params;
    }
}
